import 'package:flutter/material.dart';
import 'package:uikit/uikit.dart';

import '../../model/section_model.dart';
import '../../view_model/poi_search_cell_view_model.dart';

typedef POIHeaderClickCallback = void Function(POIHeaderType, List<POISearchCellViewModel>);

class POIHeader extends StatelessWidget {
  final POIListSectionHeaderModel header;
  final POIHeaderClickCallback callback;
  final List<POISearchCellViewModel> list;

  const POIHeader({Key? key, required this.header, required this.callback, required this.list}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return SliverToBoxAdapter(
        child: Container(
          height: 44,
          padding:
          const EdgeInsets.only(left: 12, right: 12, bottom: 12, top: 12),
          decoration: BoxDecoration(
              color: header.backgroundColor,
              borderRadius: const BorderRadius.only(
                  topLeft: Radius.circular(24),
                  topRight: Radius.circular(24)
              )
          ),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              const SizedBox(width: 4),
              if (header.imageName != null)
                T3Image.t3assets(T3AssetsNameString(
                    'assets/images/${header.imageName}.webp')),
              const SizedBox(width: 4),
              Text(
                header.title,
                style:
                TextStyle(color: header.titleColor, fontSize: 12),
              ),
              const Spacer(
                flex: 1,
              ),
              if (header.actionTitle != null)
                T3GestureDetector(
                  onTap: () {
                    if (header.type != null) {
                      callback(header.type!, list);
                    }
                  },
                  child: Container(
                    height: 26,
                    padding: const EdgeInsets.only(left: 4, right: 4),
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                        border: Border.all(color: const Color(0xFFFF8833), width: 0.5),
                        borderRadius: const BorderRadius.all(Radius.circular(13))
                    ),
                    child: Text(header.actionTitle!,
                        style: const TextStyle(
                            color: Color(0xFFFA6400),
                            fontSize: 12,
                            fontWeight: FontWeight.w500)),
                  ),
                ),
            ],
          ),
        )
    );
  }
}
